package com.xuchao.yao_jz.web;


import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.mapper.Wrapper;
import com.xuchao.yao_jz.entity.Chufang;
import com.xuchao.yao_jz.service.IChufangService;
import com.xuchao.yao_jz.vo.ResultEntity;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author Mht
 * @since 2020-03-16
 */
@RestController
@RequestMapping("/chufang")
@Slf4j
public class ChufangController {

    @Autowired
    IChufangService chufangService;

    @RequestMapping("/getChuFangList")
    public ResultEntity getChuFangList(String yaopinname){
        log.info("----------------传入处方药名称为:{}", JSON.toJSONString(yaopinname));

        String str=yaopinname.substring(0,yaopinname.length()-1);
        String[] split = str.split(",");
        List list = new ArrayList();

        for (String s : split) {
            if (StringUtils.isNotBlank(s)){
                Wrapper wrapper = new EntityWrapper();
                wrapper.eq("groupname",s);
                Chufang chufang = chufangService.selectOne(wrapper);
                if (chufang != null){
                    list.add(chufang);
                }
            }
        }
        log.info("根据名称查询list结果为:{}",JSON.toJSONString(list));
        return ResultEntity.ok(list);
    }

}
